package masterjava.common.server.gwt;

import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RPC;
import com.google.gwt.user.server.rpc.SerializationPolicy;

/**
 * User: gkislin
 * Date: 7/27/11
 */
public class ServerSerializeUtil {
    protected static final SerializationPolicy SERIALIZATION_POLICY = RPC.getDefaultSerializationPolicy();

    public static Object toSerialize(Object o) {
        if (o != null) {
            try {
                SERIALIZATION_POLICY.validateSerialize(o.getClass());
            } catch (SerializationException e) {
                return o.toString();
            }
        }
        return o;
    }
}
